﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Libs.HR;

public partial class Pages_Hr_Office_Edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AppUtils.CheckLogin();
        Title = Title + " - Cập nhật văn phòng";
        if (!IsPostBack)
        {
            btDelete.Attributes.Add("onclick", "return confirm('Bạn có đồng ý xóa?');");
            init();
        }
    }

    private void init()
    {
        var _Office = new Office() { OfficeID = AppUtils.Request("id") };
        _Office = _Office.Get();
        if (_Office == null) Response.Redirect(Constant.ADMIN_PATH + Resources.Url.OfficeList);

        txtName.Text = _Office.Name;
        txtOrder.Text = _Office.Order.ToString();
        txtAddress.Text = _Office.Address;
    }

    protected void btUpdate_Click(object sender, EventArgs e)
    {
        var _Office = new Office() { OfficeID = AppUtils.Request("id") };
        _Office = _Office.Get();
        _Office.Name = txtName.Text.Trim();
        _Office.Order = Convert.ToInt32(txtOrder.Text);
        _Office.Address = txtAddress.Text.Trim();
        _Office.Update();

        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.OfficeList);
    }

    protected void btDelete_Click(object sender, EventArgs e)
    {
        Office _Office = new Office() { OfficeID = AppUtils.Request("id") };
        _Office.Delete();
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.OfficeList);
    }

    protected void btCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.OfficeList);
    }
}
